package ihm;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JSpinner;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import metier.Collaborateur;
import metier.Tache;
import metier.Contrat;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.Dialog.ModalExclusionType;
import java.awt.Window.Type;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.SwingConstants;

public class ajoutTache extends JFrame {

	private JPanel contentPane;
	private JTextField txtNbJourHomme;
	private JTextField txtNom;
	private JTextField txtlibelleTache;
	private JButton btnAccepter;
	private JButton btnAnnuler;
	private JDialog monAjoutCollab;
	private JLabel lblNumeroContrat;
	private JLabel lblNombreJourhomme;


	/**
	 * Create the frame.
	 */
	public ajoutTache() {
		
		setType(Type.UTILITY);
		setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
		setAlwaysOnTop(true);
		setResizable(false);
		setTitle("Ajouter un collaborateur");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 291, 313);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txtNbJourHomme = new JTextField();
		txtNbJourHomme.setColumns(10);
		txtNbJourHomme.setBounds(157, 129, 107, 20);
		contentPane.add(txtNbJourHomme);
		
		txtNom = new JTextField();
		txtNom.setColumns(10);
		txtNom.setBounds(157, 36, 107, 20);
		contentPane.add(txtNom);
		
		JLabel lbNumeroTache = new JLabel("Numero tache :");
		lbNumeroTache.setFont(new Font("Segoe UI", Font.PLAIN, 11));
		lbNumeroTache.setBounds(12, 13, 135, 14);
		contentPane.add(lbNumeroTache);
		
		JLabel lblLibelleTache = new JLabel("Libelle tache");
		lblLibelleTache.setFont(new Font("Segoe UI", Font.PLAIN, 11));
		lblLibelleTache.setAlignmentX(1.0f);
		lblLibelleTache.setBounds(12, 38, 71, 14);
		contentPane.add(lblLibelleTache);
		
		JLabel lbMatriculeCollab = new JLabel("Matricule collaborateur");
		lbMatriculeCollab.setHorizontalAlignment(SwingConstants.LEFT);
		lbMatriculeCollab.setFont(new Font("Segoe UI", Font.PLAIN, 11));
		lbMatriculeCollab.setBounds(12, 69, 121, 14);
		contentPane.add(lbMatriculeCollab);
		/*
		 * Construction du bouton ajouter
		 */
		btnAccepter = new JButton("Accepter");
		btnAccepter.setEnabled(false);
		btnAccepter.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(btnAccepter.isEnabled()){
				//Collaborateur monAjout = new Collaborateur(Integer.parseInt(txtMatricule.getText()), txtNom.getText(), txtPrenom.getText());
				setVisible(false);
				}
			}
		});
		
		btnAccepter.setBounds(42, 255, 89, 23);
		contentPane.add(btnAccepter);
		/*
		 * Fermeture par le bouton annuler
		 */
		btnAnnuler = new JButton("Annuler");
		btnAnnuler.addMouseListener(new MouseAdapter() {
			@Override   
			public void mouseClicked(MouseEvent e) {
				int res = JOptionPane.showConfirmDialog(null, "Annuler l'ajout ?", "Annuler ?", JOptionPane.OK_CANCEL_OPTION);
				if (res == JOptionPane.OK_OPTION) {
					setVisible(false);
					runMaquette.maMaquette.setEnabled(true);
					runMaquette.maMaquette.toFront();
					
				}
			}
		});
		btnAnnuler.setBounds(154, 255, 89, 23);
		contentPane.add(btnAnnuler);
		/*
		 * Fermeture par la croix
		 */
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				runMaquette.maMaquette.setEnabled(true);
				runMaquette.maMaquette.toFront();
			}
		});
		txtlibelleTache = new JTextField();
		txtlibelleTache.setEnabled(false);
		txtlibelleTache.setColumns(10);
		txtlibelleTache.setBounds(157, 11, 28, 20);
		contentPane.add(txtlibelleTache);
		
		lblNumeroContrat = new JLabel("Numero contrat");
		lblNumeroContrat.setBounds(12, 101, 89, 14);
		contentPane.add(lblNumeroContrat);
		
		lblNombreJourhomme = new JLabel("Nombre Jour/Homme");
		lblNombreJourhomme.setBounds(12, 132, 119, 14);
		contentPane.add(lblNombreJourhomme);
		
		JComboBox cbxMatriculeCollab = new JComboBox();
		cbxMatriculeCollab.setBounds(157, 67, 107, 20);
		contentPane.add(cbxMatriculeCollab);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setBounds(157, 98, 107, 20);
		contentPane.add(comboBox);
	}
}
